const Topic = require("../model/topic.model");
const Collect = require("../model/collect.model");

class CollectService {
  /*  async getQuestionBank() {
    const res = await Question.findAll({
      attributes: {
        exclude: ["createdAt", "updatedAt"],
      },
    });
    return res ? res : null;
  } */

  async createCollect(collect_mes) {
    const res = await Collect.create(collect_mes);
    return res.dataValues;
  }

  async deleteUserCollect(collect_mes) {
    const res = await Collect.destroy({
      where: {
        user_id: collect_mes.user_id,
        collect_topic_id: collect_mes.collect_topic_id,
      },
    });
    return res.dataValues;
  }

  async getAllCollectId(collect_mes) {
    const res = await Collect.findAll({
      where: {
        user_id: collect_mes.user_id,
      },
    });
    let collect_arr = [];
    for (let i = 0; i < res.length; i++) {
      collect_arr[i] = res[i].dataValues.collect_topic_id;
    }
    return collect_arr ? collect_arr : null;
  }
  async getTopic(topic_id) {
    const res = await Topic.findAll({
      where: {
        id: topic_id,
      },
    });
    return res ? res[0].dataValues : null;
  }
}

module.exports = new CollectService();
